import type { CartItem } from "@/types/cart"
import { http } from "@/utils/request"

//加入购物车
export const addMemberCart = (skuId: string, count: number) => {
  return http({
    url: '/member/cart',
    method: 'POST',
    data: {
      skuId,
      count
    }
  })
}

//获取购物车列表
export const memberCartList = () => {
  return http<CartItem[]>({
    url: '/member/cart',
    method: 'GET'
  })
}

//删除/清空购物车单品
export const deleteMemberCart = (data: { ids: string[] }) => {
  return http<CartItem>({
    url: '/member/cart',
    method: 'DELETE',
    data
  })
}

//修改购物车单品
export const editMemberCart = (skuId: string, data?: { selected?: boolean, count?: number }) => {
  return http({
    url: `/member/cart/${skuId}`,
    method: 'PUT',
    data
  })
}

//购物车全选/取消全选
export const editMemberCartAll = (data: { selected: boolean }) => {
  return http({
    url: '/member/cart/selected',
    method: 'PUT',
    data
  })
}